#include <stdio.h>
#include <stdlib.h>

int *findErrorNums(int *nums, int numsSize, int *returnSize){

    int *rets = malloc(sizeof(int) * 2);
    int ret = 0;
    for (int i = 0; i < numsSize; i++) {
        ret ^= nums[i];
        ret ^= i + 1;
    }

    //找到两个数异或为1的某一位
    int mov = 0;                        //向右移动的位数
    for (int i = 0; i < 32; i++) {
        if ((ret >> i) & 1) {
            mov = i;
            break;
        }
    }

    //分离1和0为两组数
    int ret1 = 0;
    int ret0 = 0;
    for (int i = 0; i < numsSize; i++) {    //异或数组
        if ((nums[i] >> mov) & 1) {         //某位为1
            ret1 ^= nums[i];
        } else {                            //某位为0
            ret0 ^= nums[i];
        }
    }
    for (int i = 1; i <= numsSize; i++) {   //异或数列
        if ((i >> mov) & 1) {               //某位为1
            ret1 ^= i;
        } else {                            //某位为0
            ret0 ^= i;
        }
    }
    // *returnSize = 2;
    for (int i = 0; i < numsSize; i++) {    //如果出现过放第一个
        if (nums[i] == ret1) {
            rets[0] = ret1, rets[1] = ret0;
            return rets;
        }
    }
    rets[0] = ret0, rets[1] = ret1;
    return rets;
}

int main() {
    int nums[5] = {1, 2, 2, 3, 4};
    int *P = findErrorNums(nums, 5, NULL);
    printf("%d\n%d\n", P[0], P[1]);
    return 0;
}